/*
 @coding  : utf-8
 @Time    : 2023/4/20 16:07
 @Author  : Rumou
 @File    : 合并map.go
 @Description:
*/

package main

import "fmt"

func main() {
	A := map[string]int{"AA": 1, "BB": 2, "DD": 5}
	B := map[string]int{"AA": 2, "BB": 3, "CC": 4}
	C := make(map[string]int)
	for keyA, valueA := range A {
		for keyB, valueB := range B {
			if keyA == keyB {
				valueC := valueA + valueB
				C[keyA] = valueC
			}
			_, in := A[keyB]
			if !in {
				C[keyB] = B[keyB]
			}
			_, in = B[keyA]
			if !in {
				C[keyA] = A[keyA]
			}

		}
	}
	for key, value := range C {
		fmt.Printf("%s : %d\n", key, value)
	}
}
